package com.example.distillapplication.ui.activity;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;

import android.content.Intent;
import android.os.Bundle;

import com.example.distillapplication.R;
import com.example.distillapplication.ui.activity.base.BaseActivity;
import com.example.distillapplication.data.repository.DataBaseRepository;
import com.example.distillapplication.databinding.ActivityLoginBinding;
import com.example.distillapplication.ui.fragment.login.LoginListener;
import com.example.distillapplication.ui.fragment.viewpager.MainFragmentStateAdapter;
import com.example.distillapplication.ui.fragment.viewpager.RegisterListener;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

public class LoginActivity extends BaseActivity implements RegisterListener, LoginListener {
    ActivityLoginBinding activityLoginBinding;
    Intent intent;
    String[] tabTitles={"登录","注册"};
    DataBaseRepository dataBaseRepository;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_login);
        activityLoginBinding = DataBindingUtil.setContentView(this, R.layout.activity_login);

        intent = new Intent(LoginActivity.this, MainActivity.class);


        activityLoginBinding.viewpager.setAdapter(new MainFragmentStateAdapter(this));

        TabLayoutMediator tabLayoutMediator = new TabLayoutMediator(activityLoginBinding.tabLayout, activityLoginBinding.viewpager, true, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(tabTitles[position]);
                activityLoginBinding.viewpager.setCurrentItem(tab.getPosition());
            }
        });
        tabLayoutMediator.attach();

//        dataBaseRepository = new DataBaseRepository(this, mDataBaseViewModel);
//        dataBaseRepository.getAllOperationLog();
//        dataBaseRepository.getAllUserInfo();
        //dataBaseRepository.getUserInfoByAccount("root");

        mDataBaseViewModel.dataBaseRepository.getAllOperationLog();


        mSerialMessageViewModel.onDistillFlag.setValue(0);
        mSerialMessageViewModel.curSteamVolume.setValue(0.0);
        mSerialMessageViewModel.startSteamVolume.setValue(0.0);
        mSerialMessageViewModel.targetSteamVolume.setValue(0.0);
        mSerialMessageViewModel.timeSetup.postValue(false);
        mSerialMessageViewModel.steamVolumeSetup.postValue(false);

        //7个开关的状态
        mInstrumentStateViewModel.addWaterSwitchState.postValue(false);
        mInstrumentStateViewModel.valveSwitchState.postValue(false);
        mInstrumentStateViewModel.lightSwitchState.postValue(false);
        mInstrumentStateViewModel.heatSwitchState.postValue(false);
        mInstrumentStateViewModel.refrigerationSwitchState.postValue(false);
        mInstrumentStateViewModel.addCoolantSwitchState.postValue(false);
        mInstrumentStateViewModel.sodaSwitchState.postValue(false);

        mInstrumentStateViewModel.securityDoorClosed.postValue(true);
    }

    //注册后的处理
    @Override
    public void returnLoginFragment() {
        activityLoginBinding.viewpager.setCurrentItem(0);
    }

    //登录后的处理
    @Override
    public void login() {
        startActivity(intent);
        finish();
    }

}
